package com.bw.mallshop.timmer;


import android.os.Handler;
import android.os.Message;

import androidx.annotation.NonNull;

import com.bw.mallshop.mvvm.viewmodel.SplashViewModel;

import java.lang.ref.WeakReference;
import java.util.logging.LogRecord;

public
/**
 * @author Lishaohe
 * @description:
 * @date :2021/10/13 0013 下午 6:33
 *
 */
class TimeHandler extends Handler {

    private WeakReference<SplashViewModel> weakReference;
    private int time=3;
    public TimeHandler(SplashViewModel viewModel){
        weakReference = new WeakReference<>(viewModel);
    }

    @Override
    public void handleMessage(@NonNull Message msg) {
        super.handleMessage(msg);
        if (weakReference==null){
            return;
        }
        if (weakReference.get()==null){
            return;
        }
        if (msg.what==0){
            time-=1;
            weakReference.get().timeObserable.set(""+time+"S");
        }else {
            weakReference.get().skipTimmer();
        }
    }
}
